package com.cx.file.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author cx
 * @description: swagger配置类
 * @date 2021/5/17 16:47
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createFileManageRestApi() {
        return createRestApi("文件管理", "com.cx.file.controller");
    }


    public Docket createRestApi(String apiName, String basePackage) {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(authApiInfo(apiName))
                .groupName(apiName)
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo authApiInfo(String apiName) {
        return new ApiInfoBuilder()
                .title(String.format("%s测试接口", apiName))
                .description(String.format("主要提供%s测试接口功能", apiName))
                .version("1.0")
                .build();
    }
}


